New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

memize

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

memize

Unabashedly-barebones memoization library with an aim toward speed

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
131K
increased by6.45%
Maintainers
1
Weekly downloads
 
Created

What is memize?

The memize npm package is a simple utility for memoizing functions. Memoization is a technique used to speed up function execution by caching the results of expensive function calls and returning the cached result when the same inputs occur again.

What are memize's main functionalities?

Basic Memoization

This feature allows you to memoize a function so that it caches the results of expensive function calls. When the same inputs are provided again, the cached result is returned instead of recomputing the result.

const memize = require('memize');

function expensiveFunction(x) {
  console.log('Computing...');
  return x * x;
}

const memoizedFunction = memize(expensiveFunction);

console.log(memoizedFunction(5)); // Computing... 25
console.log(memoizedFunction(5)); // 25 (cached result)

Custom Cache Size

This feature allows you to specify a custom cache size for the memoized function. Once the cache size is exceeded, the oldest cached results are discarded.

const memize = require('memize');

function expensiveFunction(x) {
  console.log('Computing...');
  return x * x;
}

const memoizedFunction = memize(expensiveFunction, { maxSize: 3 });

console.log(memoizedFunction(5)); // Computing... 25
console.log(memoizedFunction(6)); // Computing... 36
console.log(memoizedFunction(7)); // Computing... 49
console.log(memoizedFunction(5)); // 25 (cached result)
console.log(memoizedFunction(8)); // Computing... 64
console.log(memoizedFunction(6)); // 36 (cached result)
console.log(memoizedFunction(7)); // 49 (cached result)
console.log(memoizedFunction(5)); // Computing... 25 (cache size exceeded, recomputed)

Other packages similar to memize

Keywords

FAQs

Package last updated on 07 Mar 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc